package com.yxhl.zoume.core.tripsmgmt.presenter.zoumebusticket;

import android.content.Context;

import com.yxhl.zoume.common.presenter.BasePresenter;
import com.yxhl.zoume.common.ui.view.BaseView;
import com.yxhl.zoume.core.tripsmgmt.view.zoumebusticket.BusRefundTicketProgressView;
import com.yxhl.zoume.data.http.rest.param.tripsmgnt.BusRefundParam;
import com.yxhl.zoume.data.http.rest.response.tirps.RefundProgressResponse;
import com.yxhl.zoume.domain.interactor.ZMSubscriber;
import com.yxhl.zoume.domain.interactor.tripsmgmt.QueryRefundProgressUseCase;

import javax.inject.Inject;

/**
 * 项目名称：Ferrari
 * Created by menggod on 17/1/10 .
 */

public class TicketRefundProgressPresenter extends BasePresenter {

    BusRefundTicketProgressView mBusRefundTicketProgressView;
    @Inject
    QueryRefundProgressUseCase mQueryRefundProgressUseCase;

    @Inject
    public TicketRefundProgressPresenter(Context context) {
        super(context);
    }

    public void queryTicketRefundProgress(String order) {

        BusRefundParam busRefundParam = new BusRefundParam();
        busRefundParam
                .setId(order)
                .setMobile(getMobile())
                .setToken(getToken());
        mQueryRefundProgressUseCase
                .execute(busRefundParam,new ZMSubscriber<RefundProgressResponse>(){
                    @Override
                    public void onCompleted() {
                        super.onCompleted();
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        mBusRefundTicketProgressView.renderRefundOnError(e.getMessage());
                    }

                    @Override
                    public void onNext(RefundProgressResponse refundProgressResponse) {
                        super.onNext(refundProgressResponse);

                        if (null!=refundProgressResponse){
                            if (refundProgressResponse.isSucc()) {
                                mBusRefundTicketProgressView.renderRefundOnSuccess(refundProgressResponse.getData());
                            }else{
                                mBusRefundTicketProgressView.renderRefundOnFailure(refundProgressResponse.getResultMessage());
                            }
                        }





                    }
                });
    }

    @Override
    public void attachView(BaseView view) {
        mBusRefundTicketProgressView = (BusRefundTicketProgressView) view;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mQueryRefundProgressUseCase.unsubscribe();
    }
}
